/**    
 * @{#} PersonalActivity.java Create on 2014-5-29 下午9:26:48    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.IntentCompat;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;
import cn.o.app.json.JsonUtil;
import cn.o.app.media.CropPhotoTask;
import cn.o.app.media.CropPhotoTask.CropPhotoListener;
import cn.o.app.media.PickPhotoTask;
import cn.o.app.media.PickPhotoTask.PickPhotoListener;
import cn.o.app.media.TakePhotoTask;
import cn.o.app.media.TakePhotoTask.TakePhotoListener;
import cn.o.app.net.INetTask;
import cn.o.app.net.NetTaskListener;
import cn.o.app.ui.OActionSheet;
import cn.o.app.ui.OActionSheet.OActionItem;
import cn.o.app.ui.OActionSheet.OnActionItemClickListener;
import cn.o.app.ui.OAlert;
import cn.o.app.ui.OAlert.OAlertListener;
import cn.o.app.ui.ODatePicker;
import cn.o.app.ui.ODatePicker.OnPickDateListener;
import cn.o.app.ui.OImageView;
import cn.o.app.util.ODateFormat;
import cn.skinapp.R;

import com.evan.common.handler.RequestHandler;
import com.evan.common.handler.callback.HandlerCallback;
import com.evan.common.utils.ImageUtils;
import com.igexin.sdk.PushManager;
import com.smiier.skin.constant.Constant;
import com.smiier.skin.intercept.RequestTaskIntercept;
import com.smiier.skin.net.UserGetTask;
import com.smiier.skin.net.UserSetTask;
import com.smiier.skin.net.UserGetTask.UserGetRequest;
import com.smiier.skin.net.UserGetTask.UserGetResponse;
import com.smiier.skin.net.UserSetTask.UserSetRequest;
import com.smiier.skin.net.UserSetTask.UserSetResponse;
import com.smiier.skin.net.entity.User;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.ui.PersonalDoctorView;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.utils.CommonUtility;

public class DoctorProfileEditActivity extends BasicActivity {

	private TextView text_doctor_name_value, text_doctor_id_value,
			text_sex_value, text_birthday_value, text_minzu_value,
			text_address_value, text_doctor_hospital_value,
			text_doctor_title_value, text_keshi_tel_value, text_good_at_value,
			text_zhiyebianhao_value, text_zigezheng_value,
			text_gongzuozheng_value, text_shenfenzheng_value, text_upload_tip,
			text_mobile_value, text_agree;

	private OImageView img_doctor_icon;

	private boolean isRegisterInit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_doctor_edit_profile);

		init();
		TextView back = (TextView) findViewById(R.id.btn_left);

		// back.setVisibility(View.GONE);
		setNavLeftBtn("我的");
		setNavTitle("个人资料");

		isRegisterInit = getIntent().getBooleanExtra(Constant.IDENTITY_KEY,
				false);

		if (isRegisterInit) {
			text_agree = (TextView) findViewById(R.id.text_agree);
			text_agree.setVisibility(View.VISIBLE);
			setNavRightBtn("提交审核");
			String content = "<font color='#7a7a7a'>点击页面右上角提交按钮，即表示你接受并同意《</font><font color='#36d49a'>皮肤科医生软件医师服务协议</font>》</font>";
			setNavLeftBtnGone();
			// 取消提示文本的显示
			// text_agree.setText(Html.fromHtml(content));
		}else{
			findViewById(R.id.profile_parent).setEnabled(false);
		}

		text_doctor_name_value = (TextView) findViewById(R.id.text_doctor_name_value);
		text_doctor_id_value = (TextView) findViewById(R.id.text_doctor_id_value);
		text_sex_value = (TextView) findViewById(R.id.text_sex_value);
		text_birthday_value = (TextView) findViewById(R.id.text_birthday_value);
		text_minzu_value = (TextView) findViewById(R.id.text_minzu_value);
		text_address_value = (TextView) findViewById(R.id.text_address_value);
		text_doctor_hospital_value = (TextView) findViewById(R.id.text_doctor_hospital_value);
		text_doctor_title_value = (TextView) findViewById(R.id.text_doctor_title_value);
		text_keshi_tel_value = (TextView) findViewById(R.id.text_keshi_tel_value);
		text_good_at_value = (TextView) findViewById(R.id.text_good_at_value);
		text_zhiyebianhao_value = (TextView) findViewById(R.id.text_zhiyebianhao_value);
		text_zigezheng_value = (TextView) findViewById(R.id.text_zigezheng_value);
		text_gongzuozheng_value = (TextView) findViewById(R.id.text_gongzuozheng_value);
		text_shenfenzheng_value = (TextView) findViewById(R.id.text_shenfenzheng_value);
		text_upload_tip = (TextView) findViewById(R.id.text_upload_tip);
		text_mobile_value = (TextView) findViewById(R.id.text_mobile_value);

		img_doctor_icon = (OImageView) findViewById(R.id.img_doctor_icon);
		if (!isRegisterInit
			//	false
				) {
			findViewById(R.id.rl_doctor_icon).setClickable(false);
			findViewById(R.id.text_doctor_name).setClickable(false);
			findViewById(R.id.text_mobile).setClickable(false);
			findViewById(R.id.text_sex).setClickable(false);
			findViewById(R.id.text_birthday).setClickable(false);
			findViewById(R.id.text_minzu).setClickable(false);
			findViewById(R.id.text_doctor_hospital).setClickable(false);
			findViewById(R.id.text_doctor_title).setClickable(false);
			findViewById(R.id.text_good_at).setClickable(false);
			findViewById(R.id.text_zhiyebianhao).setClickable(false);
			findViewById(R.id.text_zigezheng).setClickable(false);
			findViewById(R.id.text_gongzuozheng).setClickable(false);
			findViewById(R.id.text_shenfenzheng).setClickable(false);
		}
		try {
			String path = GlobalSettings.sUser.Pic;
			if (!CommonUtility.isNull(path)) {
				// text_upload_tip.setVisibility(View.GONE);
				// mBitmapUtils.display(img_doctor_icon,
				// GlobalSettings.SERVER_IMG_URL
				// + GlobalSettings.sUser.Pic + Constant.IMG_SRC,
				// new OBitmapLoadCallBack<View>());
				CommonUtility.displayHeadImage(img_doctor_icon, mBitmapUtils,
						GlobalSettings.SERVER_IMG_URL
								+ GlobalSettings.sUser.Pic + Constant.IMG_SRC,
						getResources(), GlobalSettings.sUser.Sex);
			} else {
				text_upload_tip.setVisibility(View.VISIBLE);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		GlobalSettings.login_type = GlobalSettings.LOGIN_TYPE_UNKNOWN;
	}

	@Override
	protected void onResume() {
		super.onResume();

		// MobclickAgent.onResume(this);
		if (GlobalSettings.sUser == null) {
			UserGetTask task = new UserGetTask();
			UserGetRequest req = new UserGetRequest();
			req.appname = Constant.APP_NAME;
			req.uids = new ArrayList<Long>();
			req.uids.add(GlobalSettings.sUid);
			task.addListener(new NetTaskListener<UserGetTask.UserGetRequest, UserGetTask.UserGetResponse>() {

				@Override
				public void onException(
						INetTask<UserGetRequest, UserGetResponse> task,
						Exception e) {

				}

				@Override
				public void onComplete(
						INetTask<UserGetRequest, UserGetResponse> task,
						UserGetResponse response) {
					if (response != null && response.Res.size() > 0) {
						GlobalSettings.sUser = response.Res.get(0);
						initUserView();
					}
				}
			});
			task.setRequest(req);
			add(task);
		} else {
			initUserView();
		}

	}

	private void initUserView() {
		try {
			text_doctor_name_value.setText(GlobalSettings.sUser.Name);
			text_doctor_id_value.setText(GlobalSettings.sUser.Nick);
			text_mobile_value.setText(GlobalSettings.sUser.Mobile);
			text_sex_value.setText(CommonUtility.sex
					.get(GlobalSettings.sUser.Sex));
			String date = CommonUtility.formatDate(
					GlobalSettings.sUser.Birth.toString(), 0, 10);
			if (date.equals("0001-01-01")) {
				text_birthday_value.setVisibility(View.INVISIBLE);
			} else {
				text_birthday_value.setVisibility(View.VISIBLE);
				text_birthday_value.setText(date);
			}
			text_minzu_value.setText(GlobalSettings.sUser.Nation);
			StringBuilder address = new StringBuilder();
			address.append(GlobalSettings.sUser.Province)
					.append(GlobalSettings.sUser.City)
					.append(GlobalSettings.sUser.County);
			text_address_value.setText(address);
			text_doctor_hospital_value.setText(GlobalSettings.sUser.Hospital);
			text_doctor_title_value
					.setText(CommonUtility.convertJSONArray2String(
							new JSONArray(JsonUtil
									.convert(GlobalSettings.sUser.Professional)),
							","));
			text_keshi_tel_value.setText(GlobalSettings.sUser.Mobile);
			text_good_at_value.setText(CommonUtility.convertJSONArray2String(
					new JSONArray(JsonUtil
							.convert(GlobalSettings.sUser.Skilled)), ","));
			JSONArray certificate_array = new JSONArray(
					JsonUtil.convert(GlobalSettings.sUser.Certificate));
			if (certificate_array.length() > 0) {
				/*
				 * text_zigezheng_value.setText("√");
				 * text_zigezheng_value.setTextColor(0xff1177ff);
				 */

				text_zigezheng_value.setText("已上传");
			} else {
				text_zigezheng_value.setText("未上传");
				text_zigezheng_value.setTextColor(0xffa7a7a7);
			}

			JSONArray employee_card_card = new JSONArray(
					JsonUtil.convert(GlobalSettings.sUser.Employee_Card));
			if (employee_card_card.length() > 0) {
				/*
				 * text_gongzuozheng_value.setText("√");
				 * text_gongzuozheng_value.setTextColor(0xff1177ff);
				 */

				text_gongzuozheng_value.setText("已上传");
			} else {
				text_gongzuozheng_value.setText("未上传");
				text_gongzuozheng_value.setTextColor(0xffa7a7a7);
			}

			JSONArray idcard_array = new JSONArray(
					JsonUtil.convert(GlobalSettings.sUser.IdCard));
			if (idcard_array.length() > 0) {
				/*
				 * text_shenfenzheng_value.setText("√");
				 * text_shenfenzheng_value.setTextColor(0xff1177ff);
				 */

				text_shenfenzheng_value.setText("已上传");

			} else {
				text_shenfenzheng_value.setText("未上传");
				text_shenfenzheng_value.setTextColor(0xffa7a7a7);
			}

			text_zhiyebianhao_value
					.setText(GlobalSettings.sUser.Certificate_Number);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void onClick(View view) {
		super.onClick(view);
		Intent intent = null;
		int id = view.getId();
		if (id == R.id.rl_doctor_icon) {
			onClickUserIcon();
		} else if (id == R.id.text_doctor_name) {
			intent = new Intent(activity, UpdateInfoInputActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY_PARAM_KEY, "Name");
			intent.putExtra(Constant.IDENTITY_KEY_NAV_TITLE, "更改姓名");
			startActivity(intent);
		} else if (id == R.id.text_doctor_id) {
			intent = new Intent(activity, UpdateInfoInputActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY_PARAM_KEY, "Nick");
			intent.putExtra(Constant.IDENTITY_KEY_NAV_TITLE, "更改皮肤科ID");
			startActivity(intent);
		} else if (id == R.id.text_mobile) {
			intent = new Intent(activity, RegisterFirstStepActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY_1,
					Constant.TYPE_UPDATE_MOBILE);
			startActivity(intent);
		} else if (id == R.id.text_zhiyebianhao) {
			intent = new Intent(activity, UpdateInfoInputActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY_PARAM_KEY,
					"certificate_number");
			intent.putExtra(Constant.IDENTITY_KEY_NAV_TITLE, "更改执业编号");
			startActivity(intent);
		} else if (id == R.id.text_sex) {
			intent = new Intent(activity, CommonDataChooseActivity.class);
			String[] datas = { "[\"男\",\"女\"]", "修改性别", "Sex",
					CommonDataChooseActivity.TYPE_FIXATION,
					CommonDataChooseActivity.SINGLECHOOSE,
					CommonDataChooseActivity.DATA_TYPE_SEX };
			intent.putExtra(Constant.IDENTITY_KEY, datas);
			intent.putExtra(Constant.IDENTITY_KEY_2, text_sex_value.getText().toString().trim());
			startActivity(intent);
		} else if (id == R.id.text_birthday) {
			/**
			 * 生日时间选择
			 */

			ODatePicker datePicker = new ODatePicker(getContext());
			datePicker.show();
			datePicker.setListener(new OnPickDateListener() {

				@Override
				public void onPicked(ODatePicker picker, Date d, String time) {
					String date = ODateFormat.format(d, "yyyy-MM-dd");
					text_birthday_value.setText(date);
					if (!CommonUtility.isNull(date)) {
						HashMap<String, Object> params = new HashMap<String, Object>();
						params.put("Birth", date);
						params.put(Constant.PARAM_API, "User.Set");
						params.put(Constant.PARAM_TOKEN, GlobalSettings.sToken);
						RequestTaskIntercept.requestIntercept(activity,
								Constant.URL.REQUEST, new RequestHandler(
										activity, new HandlerCallback() {

											@Override
											public void callback(Object o) {
												if (!CommonUtility.isNull(o)) {
													JSONObject object = (JSONObject) o;
													if (CommonUtility
															.response200(object)) {
														text_birthday_value
																.setVisibility(View.VISIBLE);
														CommonUtility.toast(
																activity,
																"保存成功");
														try {
															GlobalSettings.sUser = JsonUtil
																	.convertFromObject(
																			object.getJSONObject("Res"),
																			User.class);
														} catch (Exception e) {
															e.printStackTrace();
														}
													} else {
														CommonUtility.toast(
																activity,
																"保存失败");
													}
												}
											}
										}), params);
					}
				}
			});
		} else if (id == R.id.text_minzu) {
			intent = new Intent(activity, CommonDataChooseActivity.class);
			String[] datas = { Constant.URL.REQUEST_NATION_JSON, "修改民族",
					"Nation", CommonDataChooseActivity.TYPE_URL,
					CommonDataChooseActivity.SINGLECHOOSE, "" };
			intent.putExtra(Constant.IDENTITY_KEY, datas);
			startActivity(intent);
		} else if (id == R.id.text_address) {
			intent = new Intent(activity, MulitLevelDataChooseActivity.class);
			String[] datas = {
					Constant.URL.REQUEST_AREA_JSON,
					"选择省份",
					"Province" + Constant.SPLIT + "City" + Constant.SPLIT
							+ "County" };
			intent.putExtra(Constant.IDENTITY_KEY, datas);
			startActivity(intent);
		} else if (id == R.id.text_doctor_hospital) {
			intent = new Intent(activity, MulitLevelDataChooseActivity.class);
			String[] datas = { Constant.URL.REQUEST_HOSPITAL_JSON, "选择省份",
					"Hospital" };
			intent.putExtra(Constant.IDENTITY_KEY, datas);
			startActivity(intent);
		} else if (id == R.id.text_keshi_tel) {
			intent = new Intent(activity, UpdateInfoInputActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY_PARAM_KEY, "Tel");
			intent.putExtra(Constant.IDENTITY_KEY_1, InputType.TYPE_CLASS_PHONE);
			intent.putExtra(Constant.IDENTITY_KEY_NAV_TITLE, "更改科室电话");
			startActivity(intent);
		} else if (id == R.id.text_doctor_title) {
			intent = new Intent(activity, CommonDataChooseActivity.class);
			String[] datas = { Constant.URL.REQUEST_PROFESSIONAL_JSON, "职称",
					"Professional", CommonDataChooseActivity.TYPE_URL,
					CommonDataChooseActivity.SINGLECHOOSE, "" };
			intent.putExtra(Constant.IDENTITY_KEY, datas);
			startActivity(intent);
		} else if (id == R.id.text_good_at) {
			intent = new Intent(activity, CommonDataChooseActivity.class);
			String[] datas = { Constant.URL.REQUEST_SYMPTOM_JSON, "擅长科目",
					"Skilled", CommonDataChooseActivity.TYPE_URL,
					CommonDataChooseActivity.MULITCHOOSE, "" };
			intent.putExtra(Constant.IDENTITY_KEY_ITEM_SIZE, 3);
			intent.putExtra(Constant.IDENTITY_KEY, datas);
			startActivity(intent);
		} else if (id == R.id.text_zigezheng) {
			intent = new Intent(activity, UploadZhengshuActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY, "Certificate");
			intent.putExtra(Constant.IDENTITY_KEY_TITLE, "上传职称证");
			startActivity(intent);
		} else if (id == R.id.text_gongzuozheng) {
			intent = new Intent(activity, UploadZhengshuActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY, "Employee_Card");
			intent.putExtra(Constant.IDENTITY_KEY_TITLE, "上传执业证");
			startActivity(intent);
		} else if (id == R.id.text_shenfenzheng) {
			intent = new Intent(activity, UploadZhengshuActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY, "IdCard");
			intent.putExtra(Constant.IDENTITY_KEY_TITLE, "上传身份证");
			startActivity(intent);
		} else if (id == R.id.text_agree) {
			startActivity(new Intent(activity, ShengmingActivity.class));
		} else if (id == R.id.text_right) {
			try {

				/*
				 * if(CommonUtility.isNull(GlobalSettings.sUser.Pic)||CommonUtility
				 * .isNull(GlobalSettings.sUser.Name)||
				 * CommonUtility.isNull(GlobalSettings
				 * .sUser.Mobile)||CommonUtility
				 * .isNull(GlobalSettings.sUser.Birth)
				 * ||CommonUtility.isNull(GlobalSettings.sUser.Hospital)){
				 * toast("请您将个人资料填写完整"); }
				 */
				String user_icon = GlobalSettings.sUser.Pic;
				String user_name = GlobalSettings.sUser.Name;
				String user_id = GlobalSettings.sUser.Nick;
				String user_sex = GlobalSettings.sUser.Sex + "";
				String user_birthday = GlobalSettings.sUser.Birth.toString();
				String user_nation = GlobalSettings.sUser.Nation;
				StringBuilder address = new StringBuilder();
				address.append(GlobalSettings.sUser.Province)
						.append(GlobalSettings.sUser.City)
						.append(GlobalSettings.sUser.County);
				String user_address = address.toString();
				String user_hospital = GlobalSettings.sUser.Hospital;
				String user_profssional = CommonUtility
						.convertJSONArray2String(
								new JSONArray(
										JsonUtil.convert(GlobalSettings.sUser.Professional)),
								",");
				String user_keshi_tel = GlobalSettings.sUser.Tel;
				String user_good_at = CommonUtility.convertJSONArray2String(
						new JSONArray(JsonUtil
								.convert(GlobalSettings.sUser.Skilled)), ",");
				String user_zhiyebianhao = GlobalSettings.sUser.Certificate_Number;

				JSONArray certificate_array = new JSONArray(
						JsonUtil.convert(JsonUtil
								.convert(GlobalSettings.sUser.Certificate)));
				JSONArray employee_card_card = new JSONArray(
						JsonUtil.convert(JsonUtil
								.convert(GlobalSettings.sUser.Employee_Card)));
				JSONArray idcard_array = new JSONArray(
						JsonUtil.convert(JsonUtil
								.convert(GlobalSettings.sUser.IdCard)));

				if (CommonUtility.isNull(user_icon)) {
					CommonUtility.tip(activity, "请上传您的头像");
					return;
				} else if (CommonUtility.isNull(user_name)) {
					CommonUtility.tip(activity, "请填写您的姓名");
					return;
				} else if (CommonUtility.isNull(user_id)) {
				//	CommonUtility.tip(activity, "请填写您的皮肤科ID");
				//	return;
				} else if (CommonUtility.isNull(user_sex)) {
					CommonUtility.tip(activity, "请选择您的性别");
					return;
				} else if (CommonUtility.isNull(user_birthday)) {
					CommonUtility.tip(activity, "请选择您的出生日期");
					return;
				} else if (CommonUtility.isNull(user_hospital)) {
					CommonUtility.tip(activity, "请选择您所在医院");
					return;
				} else if (CommonUtility.isNull(user_profssional)) {
					CommonUtility.tip(activity, "请选择您的职称");
					return;
				} else if (CommonUtility.isNull(user_good_at)) {
					CommonUtility.tip(activity, "请选择您的擅长科目");
					return;
				} else if (CommonUtility.isNull(user_zhiyebianhao)) {
					CommonUtility.tip(activity, "请填写您的执业编号");
					return;
				} else if (certificate_array.length() == 0) {
					CommonUtility.tip(activity, "请上传您的职称证");
					return;
				} else if (employee_card_card.length() == 0) {
					CommonUtility.tip(activity, "请上传您的执业证");
					return;
				} else if (idcard_array.length() == 0) {
					CommonUtility.tip(activity, "请上传您的身份证");
					return;
				}

				/*
				 * else if (CommonUtility.isNull(user_nation)) {
				 * CommonUtility.tip(activity, "请选择您的民族"); return; } else if
				 * (CommonUtility.isNull(user_address)) {
				 * CommonUtility.tip(activity, "请选择您的居住地"); return; }
				 */

				/*
				 * else if (CommonUtility.isNull(user_keshi_tel)) {
				 * CommonUtility.tip(activity, "请输入您的科室电话"); return; }
				 */

				OAlert alert = new OAlert(activity);
				alert.setOK("确认");
				alert.setCancel("取消");
				alert.setTitle("您的申请已提交，审核通过后您便可以参与问题解答。");
				alert.show();
				alert.setListener(new OAlertListener() {

					@Override
					public boolean onOK(OAlert alert) {
						HashMap<String, Object> params = new HashMap<String, Object>();
						params.put(Constant.PARAM_API, "User.Set");
						params.put("Is_Cert", 3);
						params.put(Constant.PARAM_TOKEN, GlobalSettings.sToken);
						RequestTaskIntercept.requestIntercept(activity,
								Constant.URL.REQUEST, new RequestHandler(
										activity, new HandlerCallback() {

											@Override
											public void callback(Object o) {
												if (!CommonUtility.isNull(o)) {
													JSONObject object = (JSONObject) o;
													if (CommonUtility
															.response200(object)) {
														CommonUtility
																.toast(activity,
																		"已提交后台审核，请耐心等待");
												    serUserClientId();
													 
														try {
															GlobalSettings.sUser = JsonUtil
																	.convertFromObject(
																			object.getJSONObject("Res"),
																			User.class);
															/*Intent intent = new Intent(
																	DoctorProfileEditActivity.this,
																	GlobalSettings
																			.getActivity4Navigate(DoctorProfileEditActivity.this));
															intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
																	| IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
															startActivity(intent);*/
															
															GlobalSettings.isBangding = true;
															Intent intent = new Intent();
															intent.setClass(DoctorProfileEditActivity.this, GlobalSettings
											.getActivity4Navigate(getContext()));
															startActivity(intent);
															Log.i("testooo", "DoctorProfileEditActivity.isBangding:" + GlobalSettings.isBangding);
															
															
														} catch (Exception e) {
															e.printStackTrace();
														}
													} else {
														CommonUtility.toast(
																activity,
																"提交审核失败");
													}
												}
											}
										}), params);
						return false;
					}

					@Override
					public boolean onCancel(OAlert alert) {
						return false;
					}
				});
			} catch (Exception e) {
				toast("请您将个人资料填写完整");
				e.printStackTrace();
			}
		}
	}
	
	/*
	 * 
	 * 通知服务器端改用户的ID
	 */
	private void serUserClientId() {
		
		UserSetRequest req = new UserSetRequest();
		req.token = GlobalSettings.sToken;
		req.GT_ClientID = PushManager
				.getInstance()
				.getClientid(
						getApplicationContext());
		
		
		Log.i("testmedicinal", "login.getId:" + req.GT_ClientID);
		
		GlobalSettings.sUser.GT_ClientID = req.GT_ClientID;
		UserSetTask task = new UserSetTask();
		task.setRequest(req);
		
		Log.i("testmedicinal", "token:" + GlobalSettings.sToken);
		
		task.addListener(new NetTaskListener<UserSetTask.UserSetRequest, UserSetTask.UserSetResponse>() {

			@Override
			public void onException(
					INetTask<UserSetRequest, UserSetResponse> task,
					Exception e) {
				
				Log.i("testmedicinal", "onException:" + e.toString());

			}

			@Override
			public void onComplete(
					INetTask<UserSetRequest, UserSetResponse> task,
					UserSetResponse response) {
				
				Log.i("testmedicinal", "onComplete:" + response.Res.Name);
				
				if (response.ResultCode != 200) {
					return;
				}
			}
		});
		add(task);
		
	}
	

	protected void onClickUserIcon() {
		ArrayList<OActionItem> dataProvider = new ArrayList<OActionSheet.OActionItem>();
		OActionItem item = null;
		item = new OActionItem();
		item.setText("拍照");
		dataProvider.add(item);
		item = new OActionItem();
		item.setText("从手机相册选择");
		dataProvider.add(item);
		OActionSheet<OActionItem> actionSheet = new OActionSheet<OActionSheet.OActionItem>(
				this);
		actionSheet.setCancel("取消");
		actionSheet.setDataProvider(dataProvider);
		actionSheet.show(false, true);
		actionSheet
				.setOnActionItemClickListener(new OnActionItemClickListener<OActionSheet.OActionItem>() {

					@Override
					public void onItemClick(OActionSheet<OActionItem> sheet,
							View v, int position, OActionItem dataItem) {
						if (position == 0) {
							TakePhotoTask task = new TakePhotoTask(
									DoctorProfileEditActivity.this,
									GlobalSettings.REQUEST_CODE_TAKE_PHOTO);
							task.takePhoto();
							task.setListener(new TakePhotoListener() {

								@Override
								public void onComplete(Uri uri) {
									CropPhotoTask task = new CropPhotoTask(
											DoctorProfileEditActivity.this,
											GlobalSettings.REQUEST_CODE_CROP_PHOTO);
									task.cropPhoto(uri, 150, 150);
									task.setListener(new CropPhotoListener() {

										@Override
										public void onComplete(Uri uri) {
											uploadPic(uri.getPath());
										}
									});
								}
							});
						}
						if (position == 1) {
							PickPhotoTask task = new PickPhotoTask(
									DoctorProfileEditActivity.this,
									GlobalSettings.REQUEST_CODE_PICK_PHOTO);
							task.pickPhoto();
							task.setListener(new PickPhotoListener() {

								@Override
								public void onComplete(Uri uri) {
									CropPhotoTask task = new CropPhotoTask(
											DoctorProfileEditActivity.this,
											GlobalSettings.REQUEST_CODE_CROP_PHOTO);
									task.cropPhoto(uri, 150, 150);
									task.setListener(new CropPhotoListener() {

										@Override
										public void onComplete(Uri uri) {
											uploadPic(uri.getPath());
										}
									});
								}
							});
						}
					}
				});
	}

	protected void uploadPic(String path) {
		File f = new File(path);
		if (f.exists()) {
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(Constant.PARAM_TOKEN, // GlobalSettings.sUser.Token
					GlobalSettings.sToken);
			params.put("pic", f);
			params.put(Constant.PARAM_API, "SYS.UploadPic");
			RequestTaskIntercept.requestIntercept(activity,
					Constant.URL.REQUEST, new RequestHandler(activity,
							new HandlerCallback() {

								@Override
								public void callback(Object o) {
									if (!CommonUtility.isNull(o)) {
										try {
											JSONObject object = (JSONObject) o;
											if (CommonUtility
													.response200(object)) {
												final String path = object
														.getString(Constant.JSON_PARAM_RES);
												HashMap<String, Object> params_ = new HashMap<String, Object>();
												params_.put(
														Constant.PARAM_TOKEN,
														GlobalSettings.sToken);
												params_.put("Pic", path);
												params_.put(Constant.PARAM_API,
														"User.Set");
												RequestTaskIntercept
														.requestIntercept(
																activity,
																Constant.URL.REQUEST,
																new RequestHandler(
																		activity,
																		new HandlerCallback() {

																			@Override
																			public void callback(
																					Object o) {
																				if (!CommonUtility
																						.isNull(o)) {
																					JSONObject object = (JSONObject) o;
																					if (CommonUtility
																							.response200(object)) {
																						try {
																							GlobalSettings.sUser.Pic = path;

																						} catch (Exception e) {
																							e.printStackTrace();
																						}
																					}
																				}
																			}
																		}),
																params_);
											}
										} catch (Exception e) {
											e.printStackTrace();
										}
									}

								}
							}), params);
			Bitmap bitmap = ImageUtils
					.getRoundCornerBitMap(f.getAbsolutePath());
			img_doctor_icon.setImageBitmap(bitmap);
		}
	}

	@Override
	public void onBackPressed() {
		if (!isRegisterInit) {
			finish();
		}
	}

	/*
	 * @Override public void onPause() { super.onPause();
	 * MobclickAgent.onPause(getContext()); }
	 */
}
